﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using Raven.Client;
using Topics.Radical.Validation;
using SampleApp.MvcBackend.Data.Views;

namespace SampleApp.MvcBackend.Controllers
{
	public class CustomersController : ApiController
	{
		readonly IDocumentStore sessionFactory;

		public CustomersController( IDocumentStore sessionFactory )
		{
			Ensure.That( sessionFactory ).Named( () => sessionFactory ).IsNotNull();

			this.sessionFactory = sessionFactory;
		}

		public IEnumerable<CustomerView> Get()
		{
			using ( var session = this.sessionFactory.OpenSession() )
			{
				var customers = session.Query<CustomerView>().Take( 10 ).ToArray();

				return customers;
			}
		}

	}
}
